//  微博具体内容模型
//  WBStatus.swift
//  WeiboSwift
//
//  Created by Apple13 on 16/7/13.
//  Copyright © 2016年 yupeng. All rights reserved.
//

import UIKit


class WBStatus: NSObject {
    
    
    
    //  发布微博时间
    var created_at: String?
    //  微博id
    var id: Int64 = 0
    //  微博内容
    var text: String?
    //  来源
    var source: String?
    
    
    
    //关注的用户对象
    var user:WBUser?
    
    //转发数
    var reposts_count:Int = 0
    
    //评论数
    var comments_count:Int = 0
    
    //表态数(赞)
     var attitudes_count: Int = 0
    
    //转发微博对象
     var retweeted_status: WBStatus?
    
    
    //配图信息
    var pic_urls:[StatusPictureInfo]?
    
    //  kvc构造函数
    init(dict: [String: AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
        
    }
    
    //字典有键值不匹配的时候
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        printLog()
//        print("微博内容有字典键值不匹配")
    }
    
    
    
    
    override func setValue(value: AnyObject?, forKey key: String) {
        if key == "user"{//修改User的构造函数-- 避免user 字段被 KVO 直接设置成了字典
            
            guard let dic = value as? [String:AnyObject] else{
                return
            }
            
            user = WBUser(dict:dic)//字典转模型
        }else if key == "retweeted_status" {
            guard let dic = value as? [String: AnyObject] else {
                return
            }
            
            //  代码执行到此,一定是我们想要的字典格式
            retweeted_status = WBStatus(dict: dic)

            
        }else if key == "pic_urls"{
            guard let dicArray = value as? [[String:AnyObject]] else{
                return
            }
        //执行到此一定是正经的字典
            
            //将字典转模型
            var tempArray = [StatusPictureInfo]()
            for dict in dicArray{
                let pictureInfo = StatusPictureInfo(dict:dict)
                tempArray.append(pictureInfo)
            }
                //设置自定义属性
            pic_urls = tempArray
            
        
        }
        else {
            super.setValue(value, forKey: key)
        }

    
    }
    

}
